package com.huaguoguo.miner.monitor.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
/**
 *  描述： 通用结果输出<br>
 *  CreateDate: 2021/8/18 <br>
 *  @author huaguoguo
 */
public class Result<T> {
    public static int SUCCESS = 0;
    private int code;
    private String msg;
    private T data;
    public Result(Integer code, String msg){
        this(code,msg,null);
    }

    public Result(int code){
        this(code,"",null);
    }

    /*
     * @Description: 只输出数据
     * @param data: 输出的数据
     * @return com.nstc.nfbcm.common.model.Result<T>
     * @author 张金桂
     * @since 2021/2/7 14:38
     */
    public static<T> Result<T> success(T data){
        return new Result(SUCCESS,"ok",data);
    }
    /*
     * @Description: 只提示成功消息
     * @param msg: 提示的操作成功消息
     * @return com.nstc.nfbcm.common.model.Result<java.lang.String>
     * @author 张金桂
     * @since 2021/2/7 14:38
     */
    public static Result<String> success(String msg){
        return new Result(SUCCESS,msg,null);
    }
    /*
     * @Description: 既输出数据又提示消息
     * @param msg: 提示的消息
     * @param data: 输出的数据
     * @return com.nstc.nfbcm.common.model.Result<T>
     * @author 张金桂
     * @since 2021/2/7 14:38
     */
    public static<T> Result<T> success(String msg,T data){
        return new Result(SUCCESS,msg,data);
    }
    /*
     * @Description:  输出业务异常码编号及异常消息
     * @param code: 业务异常码
     * @param msg: 失败消息
     * @return com.nstc.nfbcm.common.model.Result<T>
     * @author 张金桂
     * @since 2021/2/7 14:38
     */
    public static<T> Result<T> fail(int code,String msg){
        return new Result(code,msg);
    }
}
